package com.acmedcare.framework.exchange.center.core.resolve;

import com.acmedcare.framework.exchange.center.core.PluginContainer;
import com.acmedcare.framework.exchange.center.core.PluginContainerMBean;
import com.acmedcare.framework.exchange.center.core.json.DefaultExtensionConvert;
import com.acmedcare.framework.exchange.center.core.json.IPluginExtensionConvert;
import com.acmedcare.framework.exchange.center.core.adapter.EmptyAdapterResolver;
import com.acmedcare.framework.exchange.center.core.adapter.IAdapterResolver;
import com.acmedcare.framework.exchange.center.core.agent.EmptyAgentResolver;
import com.acmedcare.framework.exchange.center.core.agent.IAgentResolver;
import com.acmedcare.framework.exchange.center.core.application.IApplicationResolver;
import com.acmedcare.framework.exchange.center.core.application.LocalApplicationResolver;
import com.acmedcare.framework.exchange.center.core.consumer.EmptyComsumerResolver;
import com.acmedcare.framework.exchange.center.core.consumer.IConsumerResolver;
import com.fasterxml.jackson.databind.ObjectMapper;

public class DefaultPluginBuilder {

  private IAdapterResolver adapterResolver;
  private final IPluginExtensionConvert pluginExtensionConvert;
  IAgentResolver agentResolver;
  IApplicationResolver applicationResolver;
  IConsumerResolver consumerResolver;
  final ObjectMapper objectMapper;

  public DefaultPluginBuilder(ObjectMapper objectMapper) {
    this.adapterResolver = new EmptyAdapterResolver();
    this.pluginExtensionConvert = new DefaultExtensionConvert(objectMapper);
    this.objectMapper = objectMapper;
    this.agentResolver = new EmptyAgentResolver();
    this.applicationResolver = new LocalApplicationResolver();
    this.consumerResolver = new EmptyComsumerResolver();
  }

  public DefaultPluginBuilder addAdapterResolver(IAdapterResolver adapterResolver) {

    this.adapterResolver = adapterResolver;
    return this;
  }

  public DefaultPluginBuilder addAgentResolver(IAgentResolver agentResolver) {
    this.agentResolver = agentResolver;
    return this;
  }

  public DefaultPluginBuilder addApplicationResolver(IApplicationResolver applicationResolver) {

    this.applicationResolver = applicationResolver;
    return this;
  }

  public DefaultPluginBuilder addConsumerResolver(IConsumerResolver consumerResolver) {

    this.consumerResolver = consumerResolver;
    return this;
  }

  public PluginContainerMBean build() {
    return new PluginContainer(adapterResolver, pluginExtensionConvert, agentResolver,
        applicationResolver, consumerResolver, objectMapper);
  }
}
